package us.sunrisemorning.mykancolle.kcsapi;

import java.util.ArrayList;
import java.util.List;

import com.alibaba.fastjson.JSONObject;
import com.jfinal.plugin.activerecord.Page;

import us.sunrisemorning.mykancolle.model.Basic;
import us.sunrisemorning.mykancolle.model.User;
import us.sunrisemorning.mykancolle.utils.ApiController;

public class ApiReqRanking extends ApiController {
    public void getlist() {
        User u = getCurrentUser();
        JSONObject result = new JSONObject();

        // TODO:战果排名
        Integer pageNo = getParaToInt("api_pageno");
        if (pageNo == null) {
            pageNo = u.getId().intValue() / 10 + 1;
        }
        Page<Basic> page = Basic.dao.paginate(pageNo, 10, "select * ", "from Basic order by member_id");
        List<Basic> pageData = page.getList();
        List<JSONObject> resultList = new ArrayList<>();
        for (Basic basic : pageData) {
            JSONObject data = new JSONObject();
            data.put("no", (pageNo - 1) * 10 + pageData.indexOf(basic) + 1);
            data.put("member_id", basic.getMember_id());
            data.put("level", basic.getLevel());
            data.put("rank", basic.getRank());
            data.put("nickname", basic.getNickname());
            data.put("experience", basic.getExperience());
            data.put("comment", basic.getComment());
            // 战果值
            data.put("rate", basic.getMember_id());
            data.put("flag", 0);
            // 甲章数量
            data.put("medals", 0);
            data.put("nickname_id", basic.getNickname_id());
            data.put("comment_id", basic.getComment_id());
            resultList.add(data);
        }

        result.put("list", resultList);
        result.put("disp_page", pageNo);
        result.put("count", 1000);
        result.put("page_count", 100);

        renderApiJson(result);
    }
}
